//
//  MPProgressView.m
//  M800Project
//
//  Created by 姚宗超 on 14/11/7.
//  Copyright (c) 2014年 姚宗超. All rights reserved.
//

#import "MPProgressView.h"
#import "UAProgressView.h"

@interface MPProgressView ()
@property (nonatomic, strong)UAProgressView* progressView;
@property (nonatomic, strong)UILabel* centerLabel;

@end

@implementation MPProgressView

- (instancetype)init
{
    if (self = [super init]) {
        [self addSubview:self.progressView];
        [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.leading.trailing.mas_equalTo(self);
        }];
    }
    return self;
}

- (UAProgressView *)progressView
{
    if (!_progressView) {
        _progressView = [[UAProgressView alloc] init];
        _progressView.fillOnTouch = NO;
        _progressView.borderWidth = kCircleBorderWidth;
        _progressView.lineWidth = kCircleBorderWidth;
        _progressView.borderColor = [UIColor colorWithHexString:kCircleDefaultBorderColor];
        _progressView.centralView = self.centerLabel;
        _progressView.progressChangedBlock = ^(UAProgressView *progressView, float progress)
        {
            if (progress == 1.0f) {
                [(UILabel *)progressView.centralView setTextColor:[UIColor colorWithHexString:kCircleFinishBorderColor]];
                progressView.tintColor = [UIColor colorWithHexString:kCircleFinishBorderColor];
            }
            else
            {
                [(UILabel *)progressView.centralView setTextColor:[UIColor colorWithHexString:kTextUnSelectedGrayColor]];
                progressView.tintColor = [UIColor colorWithHexString:kCircleUnfinishBorderColor];
            }
            [(UILabel *)progressView.centralView setText:[NSString stringWithFormat:@"%2.0f%%", progress * 100]];
        };
    }
    return _progressView;
}

- (UILabel *)centerLabel
{
    if (!_centerLabel) {
        _centerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)];
        _centerLabel.font = [UIFont systemFontOfSize:12.0f];
        _centerLabel.textAlignment = NSTextAlignmentCenter;
        _centerLabel.textColor = [UIColor colorWithHexString:kCircleUnfinishBorderColor];
        _centerLabel.backgroundColor = [UIColor clearColor];
    }
    return _centerLabel;
}

- (void)setProgress:(float)progress animated:(BOOL)animated
{
    [self.progressView setProgress:progress animated:animated];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
